package jly521.com;

/**
 * @author Jly
 * @date 2018/12/27  21:52
 */

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.*;
import scala.Tuple2;

import java.util.Arrays;

/**
 * Created by hadoop on 17-4-4.
 */
public class SparkWordCountLocal {

    public static void main(String[] args) {
//        String logFile = "E:\\BaiduNetdiskDownload\\1.txt"; // Should be some file on your system
        String logFile = "hdfs://master:9000/hdfsinput/file1.txt"; // Should be some file on your system
        SparkConf conf = new SparkConf().setAppName("Simple Application");
        JavaSparkContext sc = new JavaSparkContext(conf);
        JavaRDD<String> logData = sc.textFile(logFile).cache();
        System.out.println("11111111111111111");
        long numAs = 0l;
        System.out.println("11111111111111111--numAs:"+numAs);
        numAs = logData.filter(new Function<String, Boolean>() {
            public Boolean call(String s) { return s.contains("hello"); }
        }).count();

        long numBs = 0l;
        System.out.println("11111111111111111--numBs:"+numBs);
        numBs = logData.filter(new Function<String, Boolean>() {
            public Boolean call(String s) { return s.contains("world"); }
        }).count();

        System.out.println("11111111111111111--numBs:"+numBs);
        System.out.println("Lines with a: " + numAs + ", lines with b: " + numBs);

        sc.stop();
    }
}